package org.xxx.epms.gateway.config.service;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.xxx.epms.gateway.dto.AdminDetailsDto;
import org.xxx.epms.gateway.dto.AdminPermissionDto;
import org.xxx.epms.gateway.feign.AdminFeign;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

/**
 * @Description:从对应用户服务获取UserDetails
 * @author lb
 */
public class AdminDetailsService implements UserDetailsService {

    private static final Logger log = LoggerFactory.getLogger(AdminDetailsService.class);
    @Autowired
    private AdminFeign adminFeign;

    @Override
    public AdminDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        AdminDetailsDto adminDetailsDto = adminFeign.getAdminDetails(username);
        AdminDetails adminDetails =  new AdminDetails(
                adminDetailsDto.getAdminCode(),
                adminDetailsDto.getAdminPassword(),
                adminDetailsDto.getAdminResourcesList());
        return adminDetails;
    }

}
